package com.stgy.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stgy.lease.common.exception.StgyException;
import com.stgy.lease.common.result.ResultCodeEnum;
import com.stgy.lease.model.domain.ViewAppointment;
import com.stgy.lease.web.admin.dto.AppointmentSearchDto;
import com.stgy.lease.web.admin.service.ViewAppointmentService;
import com.stgy.lease.web.admin.mapper.ViewAppointmentMapper;
import com.stgy.lease.web.admin.vo.AppointmentInfoVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lingx
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2024-08-28 11:00:30
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    //条件分页查询看房预约列表
    @Override
    public Page<AppointmentInfoVo> pageItem(AppointmentSearchDto appointmentSearchDto) {
        if (appointmentSearchDto == null) {
            throw new StgyException(ResultCodeEnum.DATA_ERROR);
        }
        //1、查询看房预约的分页数据 自定义sql两表联查
        Page<AppointmentInfoVo> page = appointmentSearchDto.getPage(AppointmentInfoVo.class);
        List<AppointmentInfoVo> appointmentInfoVos = baseMapper.selectPageItem(page, appointmentSearchDto);
        page.setRecords(appointmentInfoVos);
        return page;
    }

    //根据id更新预约状态
    @Override
    public boolean updateStatusById(Long id, Integer status) {
        if (id == null || id < 0 || status == null || status < 0) {
            throw new StgyException(ResultCodeEnum.DATA_ERROR);
        }
        ViewAppointment appointment = this.getById(id);
        appointment.setAppointmentStatus(status);
        return this.updateById(appointment);
    }
}